from machine import RTC
import machine
import utime
from machine import Pin,SPI
import fb

rtc=RTC()

rtcMemory = rtc.memory()
t=rtc.datetime()
print(t)


if machine.reset_cause() == machine.DEEPSLEEP_RESET:
    cs=Pin(2,Pin.OPEN_DRAIN,0)
    a=fb.screen(256,128,0,0)
    a.print("main {0:0>2d}:{1:0>2d}:{2:0>2d}.{3}".format(t[4],t[5],t[6],t[7]))
    print("1{0:0>2d}".format(t[7]))
    cs.value(1)
    t=rtc.datetime()
    print(t)
    print("deepsleep:{0}ms".format((1000000-t[7])//1000))
    machine.deepsleep(1000)
else:

    t=rtc.datetime()
    print( "power up  {0:0>2d}:{1:0>2d}:{2:0>2d}".format(t[4],t[5],t[6]) )
    cs=Pin(2,Pin.OPEN_DRAIN,0)

    a=fb.screen(256,128,0,0)
    a.lcdinit()
    t=rtc.datetime()

    a.print("1233 {0:0>2d}:{1:0>2d}:{2:0>2d}".format(t[4],t[5],t[6]))

    print("12334 {0:0>2d}:{1:0>2d}:{2:0>2d}".format(t[4],t[5],t[6]))
    Pin(22,Pin.OPEN_DRAIN,1)
    cs.value(1)
    print("waiting...")
    utime.sleep(5)
    machine.deepsleep(500)
